const pub = {
  go: 'ok',
  fun(){
    return '好'
  },
  // 正则验证方法
  // 手机号验证
  isMobile: (str) => {
    // return /^(13[0-9]|15[012356789]|18[0123456789]|17[0123456789]|14[57])[0-9]{8}$/.test(str);
      return /^1(3|4|5|7|8|9)\d{9}$/.test(str);
  },
  // 验证url
  isUrl: (str) => {
    return /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww‌​w.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?‌​(?:[\w]*))?)/.test(str);
  },
  // 验证身份证号
  	isPersonCard: (card) => {
  	return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(card);
  },
  // 密码验证
  pwd1: (password) => {
    return /^(\w){6,16}$/.test(password);
  },
  // 字母数字和符号
  pwd16: (password) => {
    return /^(\w){1,16}$/.test(password);
  },
  pwd50: (password) => {
    return /^(\w){1,50}$/.test(password);
  },
  // 字母数字和符号
  pwd30: (password) => {
    return /^(\w){1,30}$/.test(password);
  },
  // 字母数字和符号
  pwd32: (password) => {
    return /^(\w){1,32}$/.test(password);
  },
  // 字母数字和符号
  pwd100: (password) => {
    return /^(\w){1,100}$/.test(password);
  },
  
  //获取当前时间格式化的字符串
  getCurrentTime: (timeStr)=> {
  	function g(t) { if(t<10){t = '0'+ t;}return t; }
  	Date.prototype.toLocaleString = function() {
  		return this.getFullYear() + "-" + g(this.getMonth() + 1) + "-" + g(this.getDate()) + " " + g(this.getHours()) + ":" + g(this.getMinutes()) + ":" + g(this.getSeconds());
  	};
  	var str = timeStr?timeStr:new Date().getTime();
  	var time = new Date(str);
  	time = time.toLocaleString();
  	return time;
  },
  // 获取当前日期
  getDate(type) {
	  const date = new Date();
	  let year = date.getFullYear();
	  let month = date.getMonth() + 1;
	  let day = date.getDate();

	  if (type === 'start') {
		  year = year - 60;
	  } else if (type === 'end') {
		  year = year + 2;
	  }
	  month = month > 9 ? month : '0' + month;;
	  day = day > 9 ? day : '0' + day;
	  return `${year}-${month}-${day}`;
  }
}

export default pub;